# coding=utf-8
"""
Author: Mr.夏末
@Function: APP录制脚本回放
"""

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
import time

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "127.0.0.1:62001"
caps["appPackage"] = "com.tencent.mobileqq"
caps["appActivity"] = ".activity.SplashActivity"
caps["noReset"] = "true"
caps["ensureWebviewsHavePages"] = True

#连接appium服务器（回放之前一定要启动appium服务）
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
#隐式等待
driver.implicitly_wait(30)

el1 = driver.find_element(AppiumBy.ACCESSIBILITY_ID,"请输入QQ号码或手机或邮箱")
el1.send_keys("1330618345")
el2 = driver.find_element(AppiumBy.ACCESSIBILITY_ID,"登 录")
el2.click()
el3 = driver.find_element(AppiumBy.ACCESSIBILITY_ID,"帐户及设置")
el3.click()
el4 = driver.find_element(AppiumBy.ACCESSIBILITY_ID,"设置")
el4.click()
el5 = driver.find_element(AppiumBy.ID,"com.tencent.mobileqq:id/account_switch")
el5.click()
el6 = driver.find_element(AppiumBy.ACCESSIBILITY_ID,"退出当前帐号按钮")
el6.click()
els1 = driver.find_element(AppiumBy.XPATH,"//android.widget.Button[@text='退出登录']")
els1.click()
el7 = driver.find_element(AppiumBy.ID,"com.tencent.mobileqq:id/dialogRightBtn")
el7.click()

driver.quit()